﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace BEGDC.CC.Web.UserControls.EV
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Button Button2;
		string filePath = @"D:\Template.xls";
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if( !IsPostBack )
			{
				//Do();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

//		private void Do()
//		{
//			object oMissing = System.Reflection.Missing.Value ;
//
//			Excel.ApplicationClass app = new Excel.ApplicationClass();
//			app.Application.Workbooks.Open( filePath, oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,
//				oMissing,oMissing,oMissing,oMissing,oMissing,oMissing);
//
//			Excel.Workbook book = app.Workbooks[1];
//			Excel.Worksheet sheet = (Excel.Worksheet)app.Worksheets[1];
//			
//			Excel.Range r=(Excel.Range)sheet.Cells[4,3];
//			this.Label1.Text = r.Text.ToString();
//			sheet.Cells[4,3] = "Jun1st.Feng";
//			book.Saved = true;
//			app.ActiveWorkbook.SaveCopyAs(@"D:\Test.xls");
//			app.Quit();
//
//			ReleaseResource(sheet);
//			ReleaseResource( book );
//			ReleaseResource( app );
//		}
//
//		private void ReleaseResource(object obj)
//		{
//			try
//			{
//				System.Runtime.InteropServices.Marshal.ReleaseComObject( obj );
//			}
//			catch
//			{
//				throw new Exception("Release resource error");
//			}
//			finally
//			{
//				obj = null;
//			}
//		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
//			object oMissing = System.Reflection.Missing.Value ;
//
//			Microsoft.Office.Interop.Excel.ApplicationClass app = new Microsoft.Office.Interop.Excel.ApplicationClass();
//			app.Application.Workbooks.Open( filePath, oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,
//				oMissing,oMissing,oMissing,oMissing,oMissing,oMissing);



//			BEGDC.CC.ExcelTool.IExcelExport excelTool = new BEGDC.CC.ExcelTool.ExcelExport();
//			excelTool.Open();
////			excelTool.GenerateContent(215);
//			excelTool.GenerateEVMeetingForm(34);
//			excelTool.ExportAs(@"D:\Test.xls");
//			excelTool.Close();
		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			string path = @"D:\Talk.JPG";
			System.Drawing.Image image  = System.Drawing.Image.FromFile( path );
			Graphics g = Graphics.FromImage(image);
			g.DrawImage(image, 0, 0, image.Width, image.Height);
			Font f = new Font("华文行楷", 40);
			Brush b = new SolidBrush(Color.White);
			String s = "Jun1st.Feng";
			g.DrawString(s, f, b, 20, 190);
			image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
			g.Dispose();
			image.Dispose();


		}
	}
}
